package org.ajax.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author CSY
 * @date 2024-11-18
 */
@WebServlet("/send.do")
public class AjaxSendServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获取客户端传递过来的数据
        String name = req.getParameter("name");
        String age = req.getParameter("age");

        //模拟对获取的数据进行加工处理
        String msg = name + "-" + age;

        //把数据转换为JSON字符串(略)

        //把数据以流的方式 输出到客户端浏览器钟
        PrintWriter out = resp.getWriter();
        out.write(msg);

        out.flush();
        out.close();
    }
}
